package com.yhq.basic.jvm.classload.others;

import com.sun.crypto.provider.DESCipher;
import lombok.SneakyThrows;
import sun.misc.Launcher;

import java.net.URL;

/**
 * @author hqyin
 * @date 2023/3/1 10:13 上午
 */
public class TestClassLoad {
    @SneakyThrows
    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());
        System.out.println(DESCipher.class.getClassLoader());
        System.out.println(TestClassLoad.class.getClassLoader());

        System.out.println();

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = appClassLoader.getParent();
        ClassLoader bootstrapLoader = extClassLoader.getParent();
        System.out.println(appClassLoader);
        System.out.println(extClassLoader);
        System.out.println(bootstrapLoader);

        System.out.println();
        System.out.println("bootstrapLoader load files:");
        URL[] urls = Launcher.getBootstrapClassPath().getURLs();
        for (URL url : urls) {
            System.out.println(url);
        }

        System.out.println();
        System.out.println("extClassLoader load files:");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println();
        System.out.println("appClassLoader load files:");
        System.out.println(System.getProperty("java.class.path"));

        //创建extClassLoader对象，appClassLoader对象
        Launcher launcher = Launcher.getLauncher();
        ClassLoader classLoader = launcher.getClassLoader();
        classLoader.loadClass("xxx");

    }
}
